<script setup lang="ts">
import request from '../utils/request'
import type { TchannelsApi, TchannelsItem } from '../types/index'
import { ref } from 'vue'

defineProps<{
  currId: number
}>()
const emits = defineEmits<{
  (e: 'setCurrId', id: number): void
}>()
const list = ref<TchannelsItem>([])
const getData = async () => {
  const res = await request<any, TchannelsApi>('/channels')
  list.value = res.data.channels
  emits('setCurrId', res.data.channels[0].id)
  console.log(res.data.channels)
}
getData()
</script>

<template>
  <div class="channel-nav">
    <nav class="list">
      <a
        class="item"
        :class="{ active: currId === item.id }"
        href="javascript:;"
        v-for="item in list"
        :key="item.id"
        @click="emits('setCurrId', item.id)"
      >
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>
